<?php
namespace sycapi\tools;

use sycapi\master\Loader;
use sycapi\master\Request;
use think\Validate;
use think\Model;
use sycapi\master\Exception;
class StaticFunction{
    public static function  instanceOfValidate($class){
        return self::instanceOfClassHandle($class,"validate");
    }

    public static function  instanceOfModel($class){
        return self::instanceOfClassHandle($class,"model");
    }

    protected static function instanceOfClassHandle($class,$type){
        switch (true){
            case (empty($class)||empty($type)):
                throw new Exception("判断归属类的参数丢失");
                break;
            case ($type==="validate"):
                $result = ($class instanceof Validate);
                break;
            case ($type==="model"):
                $result = ($class instanceof Model);
                break;
            default:
                $result=false;
        }
        if(!$result){
            throw new Exception("归属类错误或不存在");
        }
        return true;
    }

    public static function buildParameter($array){
        $data=[];
        $request=Request::instance();
        foreach( $array as $item=>$value ){
            $data[$item] = $request->param($value);
        }
        return $data;
    }
}